package com.real8.plusplayground.client;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;
import com.real8.plusplayground.client.activity.ActivityReadActivity;
import com.real8.plusplayground.client.activity.ActivityReadPlace;
import com.real8.plusplayground.client.miscellaneous.MiscellaneousActivity;
import com.real8.plusplayground.client.miscellaneous.MiscellaneousPlace;
import com.real8.plusplayground.client.person.PersonActivity;
import com.real8.plusplayground.client.person.PersonPlace;
import com.real8.plusplayground.client.statistics.StatisticsActivity;
import com.real8.plusplayground.client.statistics.StatisticsPlace;

/**
 * A mapping of places to activities used by this application.
 */
public class AppActivityMapper implements ActivityMapper {
	private final ClientFactory clientFactory;

	public AppActivityMapper(ClientFactory clientFactory) {
		this.clientFactory = clientFactory;
	}

	public Activity getActivity(final Place place) {
		if (place instanceof MiscellaneousPlace)
			return new MiscellaneousActivity(clientFactory,
					(MiscellaneousPlace) place);
		else if (place instanceof ActivityReadPlace)
			return new ActivityReadActivity(clientFactory,
					(ActivityReadPlace) place);
		else if (place instanceof PersonPlace)
			return new PersonActivity(clientFactory, (PersonPlace) place);
		else if (place instanceof StatisticsPlace)
			return new StatisticsActivity(clientFactory,
					(StatisticsPlace) place);
		else
			return null;
	}
}
